package com.feihao.zhou.demo02;


import java.io.*;
import java.util.Arrays;

/**
 * 使用字符缓冲流读取文件中的数据，排序后再次写到本地文件
 */
public class BufferedReadAndWriteTest {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
                new FileReader("day13-code-WriteAndRead\\123.txt"));

        String s = br.readLine();

        String[] split = s.split(" ");

        int[] arr = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            String s1 = split[i];
            int number = Integer.parseInt(s1);
            arr[i] = number;
        }

        //将装满数字的数组进行排序:
        Arrays.sort(arr);



        //将排好序的数组写入文件：
        BufferedWriter bw = new BufferedWriter(
                new FileWriter("day13-code-WriteAndRead\\321.txt"));


        /*String string = Arrays.toString(arr);
        System.out.println(string);
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            bw.write(c+" ");
        }*/


        for (int i = 0; i < arr.length; i++) {
            bw.write(arr[i] + " ");
        }
        br.close();
        bw.close();
    }
}
